| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- import { Image } from 'expo-image';
- import { useLocalSearchParams, useRouter } from 'expo-router';
- import React, { useCallback, useEffect, useState } from 'react';
- import {
- ActivityIndicator,
- Alert,
- ImageBackground,
- ScrollView,
- StatusBar,
- StyleSheet,
- Text,
- TouchableOpacity,
- View
- } from 'react-native';
- import { useSafeAreaInsets } from 'react-native-safe-area-context';
- import { Images } from '@/constants/images';
- import { confirmReceive, getOrderDetail, OrderDetail, payOrder } from '@/services/mall';
- export default function OrderDetailScreen() {
- const { tradeNo } = useLocalSearchParams<{ tradeNo: string }>();
- const router = useRouter();
- const insets = useSafeAreaInsets();
- const [loading, setLoading] = useState(true);
- const [data, setData] = useState<OrderDetail | null>(null);
- const loadData = useCallback(async () => {
- if (!tradeNo) return;
- setLoading(true);
- try {
- const detail = await getOrderDetail(tradeNo);
- setData(detail);
- } catch (error) {
- console.error('加载订单详情失败:', error);
- }
- setLoading(false);
- }, [tradeNo]);
- useEffect(() => {
- loadData();
- }, [loadData]);
- // 去支付
- const handlePay = async () => {
- if (!data) return;
- try {
- const result = await payOrder(data.tradeNo, 'ALIPAY');
- if (result?.paySuccess) {
- Alert.alert('成功', '支付成功');
- loadData();
- }
- } catch (error) {
- console.error('支付失败:', error);
- Alert.alert('错误', '支付失败');
- }
- };
- // 确认收货
- const handleReceive = () => {
- Alert.alert('提示', '确认已收到商品?', [
- { text: '取消', style: 'cancel' },
- {
- text: '确认',
- onPress: async () => {
- try {
- await confirmReceive(tradeNo!);
- Alert.alert('成功', '确认收货成功');
- loadData();
- } catch (error) {
- console.error('确认收货失败:', error);
- }
- },
- },
- ]);
- };
- const goBack = () => {
- router.back();
- };
- if (loading) {
- return (
- <View style={styles.loadingContainer}>
- <ActivityIndicator size="large" color="#fff" />
- </View>
- );
- }
- if (!data) {
- return (
- <View style={styles.loadingContainer}>
- <Text style={styles.errorText}>订单不存在</Text>
- </View>
- );
- }
- return (
- <View style={styles.container}>
- <StatusBar barStyle="light-content" />
- <ImageBackground
- source={{ uri: Images.mine.kaixinMineBg }}
- style={styles.background}
- resizeMode="cover"
- >
- {/* 顶部导航 */}
- <View style={[styles.header, { paddingTop: insets.top }]}>
- <TouchableOpacity style={styles.backBtn} onPress={goBack}>
- <Text style={styles.backText}>←</Text>
- </TouchableOpacity>
- <Text style={styles.headerTitle}>订单详情</Text>
- <View style={styles.placeholder} />
- </View>
- <ScrollView style={styles.scrollView} showsVerticalScrollIndicator={false}>
- {/* 订单状态 */}
- <View style={styles.statusSection}>
- <Text style={styles.statusText}>{data.statusText}</Text>
- </View>
- {/* 收货地址 */}
- {data.address && (
- <ImageBackground
- source={{ uri: Images.common.itemBg }}
- style={styles.section}
- resizeMode="stretch"
- >
- <Text style={styles.sectionTitle}>收货信息</Text>
- <View style={styles.addressInfo}>
- <Text style={styles.addressName}>
- {data.address.contactName} {data.address.contactNo}
- </Text>
- <Text style={styles.addressDetail}>
- {data.address.province}{data.address.city}{data.address.district}{data.address.address}
- </Text>
- </View>
- </ImageBackground>
- )}
- {/* 商品信息 */}
- <ImageBackground
- source={{ uri: Images.common.itemBg }}
- style={styles.section}
- resizeMode="stretch"
- >
- <Text style={styles.sectionTitle}>商品信息</Text>
- <View style={styles.goodsItem}>
- <Image source={data.goodsCover} style={styles.goodsImage} contentFit="cover" />
- <View style={styles.goodsInfo}>
- <Text style={styles.goodsName} numberOfLines={2}>{data.goodsName}</Text>
- <View style={styles.goodsBottom}>
- <Text style={styles.goodsPrice}>¥{data.paymentAmount}</Text>
- <Text style={styles.goodsQty}>x{data.quantity}</Text>
- </View>
- </View>
- </View>
- </ImageBackground>
- {/* 订单信息 */}
- <ImageBackground
- source={{ uri: Images.common.itemBg }}
- style={styles.section}
- resizeMode="stretch"
- >
- <Text style={styles.sectionTitle}>订单信息</Text>
- <View style={styles.infoRow}>
- <Text style={styles.infoLabel}>订单编号</Text>
- <Text style={styles.infoValue}>{data.tradeNo}</Text>
- </View>
- <View style={styles.infoRow}>
- <Text style={styles.infoLabel}>下单时间</Text>
- <Text style={styles.infoValue}>{data.createTime}</Text>
- </View>
- <View style={styles.infoRow}>
- <Text style={styles.infoLabel}>实付金额</Text>
- <Text style={[styles.infoValue, styles.priceText]}>¥{data.paymentAmount}</Text>
- </View>
- </ImageBackground>
- <View style={{ height: 100 }} />
- </ScrollView>
- {/* 底部操作栏 */}
- {(data.status === 1 || data.status === 3) && (
- <View style={[styles.bottomBar, { paddingBottom: insets.bottom + 10 }]}>
- {data.status === 1 && (
- <TouchableOpacity style={styles.payBtn} onPress={handlePay} activeOpacity={0.8}>
- <ImageBackground
- source={{ uri: Images.common.loginBtn }}
- style={styles.payBtnBg}
- resizeMode="stretch"
- >
- <Text style={styles.payBtnText}>去支付</Text>
- </ImageBackground>
- </TouchableOpacity>
- )}
- {data.status === 3 && (
- <TouchableOpacity style={styles.payBtn} onPress={handleReceive} activeOpacity={0.8}>
- <ImageBackground
- source={{ uri: Images.common.loginBtn }}
- style={styles.payBtnBg}
- resizeMode="stretch"
- >
- <Text style={styles.payBtnText}>确认收货</Text>
- </ImageBackground>
- </TouchableOpacity>
- )}
- </View>
- )}
- </ImageBackground>
- </View>
- );
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#1a1a2e',
- },
- background: {
- flex: 1,
- },
- loadingContainer: {
- flex: 1,
- backgroundColor: '#1a1a2e',
- justifyContent: 'center',
- alignItems: 'center',
- },
- errorText: {
- color: '#999',
- fontSize: 16,
- },
- header: {
- flexDirection: 'row',
- alignItems: 'center',
- justifyContent: 'space-between',
- paddingHorizontal: 15,
- paddingBottom: 10,
- },
- backBtn: {
- width: 40,
- height: 40,
- justifyContent: 'center',
- alignItems: 'center',
- },
- backText: {
- color: '#fff',
- fontSize: 24,
- },
- headerTitle: {
- color: '#fff',
- fontSize: 18,
- fontWeight: '600',
- },
- placeholder: {
- width: 40,
- },
- scrollView: {
- flex: 1,
- },
- statusSection: {
- backgroundColor: '#ff6b00',
- padding: 20,
- marginHorizontal: 15,
- borderRadius: 12,
- alignItems: 'center',
- },
- statusText: {
- color: '#fff',
- fontSize: 18,
- fontWeight: '600',
- },
- section: {
- marginTop: 10,
- marginHorizontal: 15,
- padding: 15,
- borderRadius: 12,
- overflow: 'hidden',
- },
- sectionTitle: {
- color: '#333',
- fontSize: 15,
- fontWeight: '600',
- marginBottom: 12,
- },
- addressInfo: {},
- addressName: {
- color: '#333',
- fontSize: 15,
- fontWeight: '500',
- },
- addressDetail: {
- color: '#666',
- fontSize: 13,
- marginTop: 6,
- lineHeight: 18,
- },
- goodsItem: {
- flexDirection: 'row',
- },
- goodsImage: {
- width: 80,
- height: 80,
- borderRadius: 8,
- backgroundColor: '#fff',
- },
- goodsInfo: {
- flex: 1,
- marginLeft: 12,
- justifyContent: 'space-between',
- },
- goodsName: {
- color: '#333',
- fontSize: 14,
- lineHeight: 20,
- },
- goodsBottom: {
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- },
- goodsPrice: {
- color: '#ff6b00',
- fontSize: 16,
- fontWeight: '600',
- },
- goodsQty: {
- color: '#666',
- fontSize: 13,
- },
- infoRow: {
- flexDirection: 'row',
- justifyContent: 'space-between',
- paddingVertical: 8,
- },
- infoLabel: {
- color: '#666',
- fontSize: 13,
- },
- infoValue: {
- color: '#333',
- fontSize: 13,
- },
- priceText: {
- color: '#ff6b00',
- fontWeight: '600',
- },
- bottomBar: {
- position: 'absolute',
- bottom: 0,
- left: 0,
- right: 0,
- flexDirection: 'row',
- justifyContent: 'flex-end',
- paddingHorizontal: 15,
- paddingTop: 10,
- backgroundColor: 'rgba(0,0,0,0.3)',
- },
- payBtn: {
- width: 120,
- height: 45,
- overflow: 'hidden',
- },
- payBtnBg: {
- width: '100%',
- height: '100%',
- justifyContent: 'center',
- alignItems: 'center',
- },
- payBtnText: {
- color: '#fff',
- fontSize: 15,
- fontWeight: '600',
- },
- });
|